﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using ElectronicCommerce.Framework.Payment.Contract.DataContract;

namespace ElectronicCommerce.Framework.Payment.Configuration
{
    /// <summary>
    /// 支付类型
    /// </summary>
    [XmlRoot("payment")]
    public class PaymentMode
    {
        public PaymentMode()
        {
            this.EnvType = GatewayEnvType.Product;
        }

        /// <summary>
        /// 支付代码
        /// </summary>
        [XmlAttribute("code")]
        public string Code { get; set; }

        /// <summary>
        /// 支付名称
        /// </summary>
        [XmlAttribute("name")]
        public string Name { get; set; }

        /// <summary>
        /// 支付类型全名
        /// </summary>
        [XmlAttribute("type")]
        public string TypeFullName { get; set; }

        private Type type = null;
        /// <summary>
        /// 支付类型
        /// </summary>
        public Type Type
        {
            get
            {
                if (type == null)
                {
                    try
                    {
                        type = Type.GetType(TypeFullName);
                    }
                    catch
                    {
                        type = null;
                    }
                }

                return type;
            }
        }

        /// <summary>
        /// 支付描述
        /// </summary>
        [XmlAttribute("description")]
        public string Description { get; set; }

        /// <summary>
        /// 支付率
        /// </summary>
        [XmlAttribute("payRate")]
        public decimal PayRate { get; set; }

        /// <summary>
        /// 是在线支付
        /// </summary>
        [XmlAttribute("isOnlinePay")]
        public bool IsOnlinePay { get; set; }

        /// <summary>
        /// 是否激活
        /// </summary>
        [XmlAttribute("isActive")]
        public bool IsActive { get; set; }

        /// <summary>
        /// 请求网关的环境类型
        /// </summary>
        [XmlAttribute("envType")]
        public GatewayEnvType EnvType { get; set; }

        /// <summary>
        /// 网关请求类型
        /// </summary>
        [XmlAttribute("requestType")]
        public GatewayRequestType RequestType { get; set; }

        /// <summary>
        /// 网关返回请求类型
        /// </summary>
        [XmlAttribute("callbackRequestType")]
        public GatewayRequestType CallbackRequestType { get; set; }

        /// <summary>
        /// 请求编码类型
        /// </summary>
        [XmlAttribute("contentEncoding")]
        public string ContentEncoding { get; set; }

        /// <summary>
        /// 卖者支付代号(商户号)
        /// </summary>
        [XmlAttribute("sellerCode")]
        public string SellerCode { get; set; }

        /// <summary>
        /// 卖者支付Email
        /// </summary>
        [XmlAttribute("sellerEmail")]
        public string SellerEmail { get; set; }

        /// <summary>
        /// 卖者密钥
        /// </summary>
        [XmlAttribute("sellerKey")]
        public string SellerKey { get; set; }
    }
}
